// components/support/index.js
import { getSystemInfo } from '../../utils/getSystemInfo';
import { request } from '../../utils/request';
Component({

    /**
     * 组件的属性列表
     */
    properties: {

    },

    /**
     * 组件的初始数据
     */
    data: {
        show: false,
        actions: [],
        phone: "",
    },
    lifetimes: {
        // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
        attached: function () { 
            
        },
        ready: function () {
            this.getSysConfigInfo()
            // console.log(this.data.defaultAddress)
        },
        moved: function () { 
            //console.log("moved")
        },
        detached: function () { 
            //console.log("detached")
        },
    },
    /**
     * 组件的方法列表
     */
    methods: {
        getSysConfigInfo(fn) {
            request({
                url: "/commonApi/getSysConfigInfo",
                method: "GET",
                data: {
                    configKey: "ecard_telephone"
                }
            }).then(res => {
                if(res.code == 0){
                    this.setData({
                        phone: res.data.configValue
                    })
                    
                }
            }).catch(error => {
                // console.log(error)
            })
        },
        /**
         * 拨打电话
         */
        makePhoneCall(e) {
            console.log(e)
            let { phone } = this.data;
            if(!phone){
                wx.showToast({
                    title: "暂无联系方式",
                    icon: 'none',
                    duration: 2000
                })
                return
            }
            getSystemInfo({
                android: () => {
                    let actions = [
                        { name: phone, color: '#999', disabled: true },
                        { name: '呼叫', color: '#000' },
                    ]
                    this.setData({
                        show: true,
                        actions
                    })
                },
                ios: () => {
                    wx.makePhoneCall({
                        phoneNumber: phone
                    })
                }
            })
        },
        onSelect(e) {
            console.log(e)
            this.setData({
                show: false
            })
            wx.makePhoneCall({
                phoneNumber: this.data.phone
            })
        },
        onCancel() {
            this.setData({ show: false });
        },
    }
})